#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'

/**
 * 图书管理员，字符串操作，子串
 * @return
 */
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, q;
    string a("hello");
    assert(a.substr(3, 5) == "lo");
    while (cin >> n >> q) {
        vector<string> s(n);
        for (auto &e:s)cin >> e;
        sort(s.begin(), s.end());
        while (q--) {
            int m;
            string t;
            cin >> m >> t;
            bool flag = false;
            for (int i = 0; i < n; i++) {
                if (s[i].substr(s[i].size() - m) == t) {
                    flag = true;
                    cout << s[i] << endl;
                    break;
                }
            }
            if (!flag) {
                cout << -1 << endl;
            }
        }
    }
    return 0;
}